<template>
    <div>
        <el-container>

            <el-aside  width="200px" style="background-color: rgb(238, 241, 246)">
                <!--            侧边导航栏-->
                <el-menu style="height: 600px" :unique-opened="false" :router="true" :default-openeds="['0','1']">
<!--                    <el-menu-item index="login">-->
<!--                        <i class="el-icon-place"></i>-->
<!--                        <span slot="title">登录</span>-->
<!--                    </el-menu-item>-->
                    <el-menu-item index="/">
                        <i class="el-icon-s-home"></i>
                        <span slot="title">首页</span>
                    </el-menu-item>
                </el-menu>
            </el-aside>
        <el-container style="margin-left: 25%">

            <div id="game">
                <div id="title">
                    <p>{{garbageName}}</p>
                </div>
                <div id="control">
                    <button type="button" @click="startPlay" class="btn">开始</button>
                    <button type="button" @click="stopPlay" class="btn">停止</button>
                </div>
                <div id="box">
                    <img @mouseover="over(1)" @mouseleave="leave()" @click="sorting('厨余垃圾', 1)" src="/static/img/chuyu.jpg">
                    <img @mouseover="over(2)" @mouseleave="leave()" @click="sorting('可回收垃圾', 2)" src="/static/img/kehuishou.jpg">
                    <img @mouseover="over(3)" @mouseleave="leave()" @click="sorting('其它垃圾', 3)" src="/static/img/qita.jpg">
                    <img @mouseover="over(4)" @mouseleave="leave()" @click="sorting('有害垃圾', 4)" src="/static/img/youhai.jpg">
                </div>

                <div id="judge">
                    <div class="hand">
                        <img v-show="isShow==1" src="/static/img/hand.jpg">
                        <br>
                        <img v-show="isTrue==1" src="/static/img/yes.jpg">
                        <img v-show="isFalse==1" src="/static/img/no.jpg">
                        <br>
                        <img class="blank" src="/static/img/blank.jpg">
                    </div>
                    <div class="hand">
                        <img v-show="isShow==2" src="/static/img/hand.jpg">
                        <br>
                        <img v-show="isTrue==2" src="/static/img/yes.jpg">
                        <img v-show="isFalse==2" src="/static/img/no.jpg">
                        <br>
                        <img class="blank" src="/static/img/blank.jpg">
                    </div>
                    <div class="hand">
                        <img v-show="isShow==3" src="/static/img/hand.jpg">
                        <br>
                        <img v-show="isTrue==3" src="/static/img/yes.jpg">
                        <img v-show="isFalse==3" src="/static/img/no.jpg">
                        <br>
                        <img class="blank" src="/static/img/blank.jpg">
                    </div>
                    <div class="hand">
                        <img v-show="isShow==4" src="/static/img/hand.jpg">
                        <br>
                        <img v-show="isTrue==4" src="/static/img/yes.jpg">
                        <img v-show="isFalse==4" src="/static/img/no.jpg">
                        <br>
                        <img class="blank" src="/static/img/blank.jpg">
                    </div>

                </div>

                <div v-if="count!=0" id="text">
                    <textarea id="area" v-model="records" disabled></textarea>
                </div>

            </div>

        </el-container>

        </el-container>


    </div>

</template>

<script>
    export default {
        data() {
            return {
                isShow: 0,
                garbage:[] ,
                garbageName: '',
                isTrue: 0,
                isFalse: 0,
                resultFlag: 0,
                lotteryTimer: null,
                count: 0,
                records: ' '
            }
        },
        created() {
            this.getSortList();
        },
        methods:{
            async getSortList() {
                const {data: res} = await this.$http.get('/garbage/allGarbage')
                if (res.status !== 200) {
                    return this.$message.error(res.msg + '，获取垃圾信息列表失败!')
                }

                this.garbage = res.data.garbage
                console.log(res.data)
            },
            startPlay: function () {
                this.resultFlag = 0;
                if (!this.lotteryTimer) {
                    this.lotteryTimer = setInterval(this.lottery, 500);
                }
                this.isTrue = 0;
                this.isFalse = 0;
            },
            stopPlay: function () {
                clearInterval(this.lotteryTimer);
                this.lotteryTimer = null;
            },
            sorting: function (sortName, garbageNum) {
                this.resultFlag = 0;
                var textarea = document.getElementById('area');
                if(this.garbage[this.lotteryNumber].sortName == sortName){
                    this.count++;
                    this.isTrue = garbageNum;
                    this.isFalse = 0;
                    this.records += "记录编号："+this.count+"      用途："+this.garbage[this.lotteryNumber].sortInfo+"      名称："+this.garbage[this.lotteryNumber].garbageName + "      所选类型："+sortName +"      结果：正确"+" \n ";
                }else{
                    this.count++;
                    this.resultFlag = 0;
                    this.isFalse = garbageNum;
                    this.records += "记录编号："+this.count+"      用途："+this.garbage[this.lotteryNumber].sortInfo+"      名称："+this.garbage[this.lotteryNumber].garbageName + "      所选类型："+sortName +"      结果：错误"+" \n ";

                }
                textarea.scrollTop = textarea.scrollHeight;
            },
            lottery: function () {
                this.lotteryNumber = Math.floor(Math.random() * this.garbage.length);
                this.garbageName = this.garbage[this.lotteryNumber].garbageName;
            },
            over:function (num) {
                this.isShow=num;
            },
            leave:function () {
                this.isShow=0;
            }
        }

    }
</script>

<style scoped>
    #title{
        /*margin-left: %;*/
        width: 332px;
        height: 90px;
        border-color: #888888;
        border-style:solid;
        border-width:2px;
        text-align: center;
        font-size: 30px;
        color: #2D93CA;
    }
    #control{
        /*margin-left: 10%;*/
        margin-top: 1px;
        width: 341px;
        height: 50px;
    }
    #box{
        /*margin-left: 10%;*/
        margin-top: 1px;
    }
    .btn{
        width: 49.2%;
        height: 100%;
        border-color: #888888;
        border-style:solid;
        border-width:2px;
        color: black;
        font-size: 20px;
    }
    img{
        width: 80px;
        height: 150px;
        border-color: #888888;
        border-style:solid;
        border-width:2px;
    }

    #judge{
        /*margin-top: -1px;*/
        width: 351px;
        height: 300px;
    }

    .hand{
        width: auto;
        display:inline-block;
        margin-right: 7px;
        float: left;
        /*height: 80px;*/
    }
    .hand img{
        width: 80px;
        height: 90px;
        display:inline-block;
        border: none;
    }
    .blank{
        border: none;
        width: auto;

    }
    #text{
        position: relative;
        bottom: 5%;
        right: 20%;
    }
    textarea{
        height: 100px;
        width: 1000px;
        resize: none;
    }
</style>
